#ifndef SCANNER_H
#define SCANNER_H

#include "Token.h"
#include "Automat.h"
#include "../Puffer/Buffer.h"
#include "../Symtable/Storage.h"
#include "../Symtable/SymTable.h"

class Scanner {
public:
	virtual ~Scanner() {
	}
	// creates token
	virtual bool nextToken(Token& t) = 0;
	// releases token (not implemented)
	virtual void freeToken(Token* t) = 0;
};

class IScanner {
public:
	virtual ~IScanner() {
	}
	virtual void mkToken(TokenType tt, Token* t) = 0;
	// tells the buffer to unget a char
	virtual void ungetChar(size_t i) = 0;
	// reached end
	virtual void stop() = 0;
};

class ScannerImp: public Scanner, public IScanner {
public:
	ScannerImp(Buffer &buffer);
	virtual ~ScannerImp();

	virtual bool nextToken(Token& t);
	virtual void freeToken(Token* t);

	virtual void mkToken(TokenType tt, Token* t);
	virtual void ungetChar(size_t i);
	virtual void stop();
private:
	Automat* automat;
	SymTable* symTable;
	Buffer& buffer;
	Storage infoStorage;
	Storage lexemStorage;

	size_t line;
	size_t column;
	size_t prevColumn;

	size_t tokenLenght;
	TokenType type;
	char c;

	// add to line
	void increaseRowLineCounter(char c);
	// delete from line
	void decreaseRowLineCounter();
};

#endif
